const app = getApp()
Page({
  ...app.globalData.function,
  data: {
    ...app.globalData.config,
    current: '1',
    list: [
      {
        productId: 20,
        productName: "百兴贷【新品】",
        logo: "https://img0.baidu.com/it/u=467209302,1730869215&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800",
        interestYear: "23%-13%",
        quota: "30万"
      }
    ],
    main_hidden:false,
    empty_hidden: true,
    companyName: '',
    count:0
  },
  toProdunctDetail(ev) {
    let info = ev.currentTarget.dataset;
    let navigateUrl = '/pagesProduct/index?';
    for (let key in info) {
        info[key] = encodeURIComponent(info[key]);
        navigateUrl += key + '=' + info[key] + '&';
    }
    navigateUrl = navigateUrl.substring(0, navigateUrl.length - 1);
    wx.navigateTo({
        url: navigateUrl
    });
  },

  showResult(params) {
    var that = this;

    that.setData({
      list:[],
      count:0
    });

    wx.request({
      method: 'POST',
      url: app.globalData.context + '/bu/product/match',
      data: params,
      success: function(res) {
        console.log(res)
        var result = res.data;
        if (result.success) {
          if (result.data == null || result.data.length <= 0) {
            that.setData({
              main_hidden: true,
              empty_hidden: false
            });
          } else {
            var list = [];
            result.data.forEach(it => {
              list.push(
                {
                  productId: it.productId,
                  productName: it.productName,
                  logo: app.globalData.context + '/setting/file/output?fileUrl=' + it.logo,
                  interestYear: it.interestYear,
                  quota: it.quota
                }
              );
            });
            that.setData({
              main_hidden: false,
              list: list,
              count: list.length
            });
          }
        }
      }

    })
  },

  onLoad(e){
    this.setData({
      companyName: decodeURIComponent(e.companyName)
    });
    this.showResult(e);
  },
  onShareAppMessage() {
    return {
      title: '企运融'
    }
  },
  onShareTimeline() {}
})